package com.pyue.eam.regi;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pyue.eam.admin.api.entity.regi.CqTaskLibEntity;
import com.pyue.eam.regi.module.region.mapper.EamRegionMapper;
import com.pyue.eam.app.service.AppUserService;
import com.pyue.eam.common.data.tenant.TenantContextHolder;
import com.pyue.eam.regi.service.CqTaskLibService;
import com.pyue.eam.regi.module.region.utils.TaskPriceUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.stream.Collectors;

@SpringBootTest
@Slf4j
public class TaskPriceCount {
    @Autowired
    private CqTaskLibService cqTaskLibService;
    @Autowired
    private EamRegionMapper eamRegionMapper;
    @Autowired
    private AppUserService appUserService;

    @Test
    public void getAllRegiWXOpenId() {
        TenantContextHolder.setTenantId(1735515182907543553L);
        System.out.println(appUserService.getAllRegiWxOpenId());
    }

    // @Test
    // public void testPrice() {
    //     CqTaskLibEntity taskLib = cqTaskLibService.getById("1736611734558920705");
    //
    //     Double countPrice = cqTaskLibService.cultCountPrice(taskLib);
    //     System.out.println(taskLib);
    // }


    @Test
    public void testRegionList() {
        System.out.println(eamRegionMapper.selectList(null));
    }

    @Test
    public void testRegion() {

        final List<TreeNode<String>> treeNodeList =
                eamRegionMapper.selectList(Wrappers.emptyWrapper()).stream().filter(area -> !area.getCode().equals(area.getPCode())).map(area -> {
            TreeNode<String> node = new TreeNode<>();
            node.setId(area.getCode());
            node.setParentId(area.getPCode());
            node.setWeight(area.getCode());
            node.setName(area.getName());
            return node;
        }).collect(Collectors.toList());
        List<Tree<String>> build = TreeUtil.build(treeNodeList, "0");
        System.out.println(build);
    }


}
